package com.beerandjesus.sportofkings.handicapper.factory.brisnet.singlefile;

import com.beerandjesus.sportofkings.handicapper.model.KeyTrainerStatistics;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.KeyTrainerStatisticsCategory;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.KeyTrainerStatisticsImpl;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class KeyTrainerStatisticsFactoryImpl extends AbstractObjectFactoryImpl implements KeyTrainerStatisticsFactory {

    private static final int FIRST_INDEX = 1337;

    /* (non-Javadoc)
     * @see com.beerandjesus.sportofkings.handicapper.factory.brisnet.singlefile.KeyTrainerStatisticsFactory#getKeyTrainerStatistics(java.lang.String)
     */
    public List<KeyTrainerStatistics> getKeyTrainerStatistics(String line) {
        String[] values = getValues(line);

        return getKeyTrainerStatistics(values);
    }

    public List<KeyTrainerStatistics> getKeyTrainerStatistics(
            String[] values) {
        List<KeyTrainerStatistics> list = new ArrayList<KeyTrainerStatistics>();
        int idx = FIRST_INDEX;
        for (int i = 0; i < 6; i++) {
            KeyTrainerStatisticsImpl k = new KeyTrainerStatisticsImpl();
            k.setCategory(KeyTrainerStatisticsCategory.fromCode(val(values, idx++)));
            k.setNumStarts(val(values, idx++));
            k.setWinPercentage(val(values, idx++));
            k.setInTheMoneyPercentage(val(values, idx++));
            k.setTwoDollarROI(val(values, idx++));
            list.add(k);
        }
        return list;
    }

}
